/*
 * Copyright 2006 Stefan Arentz <http://stefan.arentz.nl>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package test.services.calculator;

import com.polarrose.spring.remoting.rest.annotations.RestService;
import com.polarrose.spring.remoting.rest.annotations.RestAction;
import com.polarrose.spring.remoting.rest.annotations.HttpMethod;
import com.polarrose.spring.remoting.rest.annotations.RestUriParam;

@RestService
public class Calculator
{
    // POST /calculator/add/123/456 -> 589 (text/plain)

    @RestAction(method = HttpMethod.POST, template = "/add/{a}/{b}")
    public double add(@RestUriParam("a") double a, @RestUriParam("a") double b)
    {
        return a + b;
    }

    // POST /calculator/add/1,2,3,4,5 -> 15 (text/plain)

    @RestAction(method = HttpMethod.POST, template = "/add/{values}")
    public double add(@RestUriParam("values") double ... value)
    {
        double total = 0;
        for (double v : value) {
            total += v;
        }
        return total;
    }
}
